package com.fauks.ssm.springbyanno.condition;

import com.fauks.ssm.springbyanno.bean.Dog;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * 手动注册到容器中
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        //判断容器中是否存在某个bean
        System.out.println(registry.containsBeanDefinition("com.fauks.demo.springbyanno.bean.Yellow"));
        System.out.println(registry.containsBeanDefinition("yello"));
        //将bean注册到容器中
        BeanDefinition beanDefinition = new RootBeanDefinition(Dog.class);
        registry.registerBeanDefinition("dog", beanDefinition);
    }
}
